package scau.jump.securitytrace;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.securitytrace.model.Address;

public class AddressModelToAdd extends AbstractTableModel {

	private static final long serialVersionUID = 6285441594259688626L;
	private List<Address> list = new ArrayList<Address>();
	private String[] columns = new String[] { "登录点名称", "值"};
	@SuppressWarnings("rawtypes")
	private Class[] types = new Class [] {java.lang.String.class, java.lang.String.class};
	private boolean[] canEdit = new boolean [] {true, true};
	
	public AddressModelToAdd() {
	}

	public AddressModelToAdd(ArrayList<Address> list) {
		this();
		this.list = list;
	}
	
	public int getRowCount() {
		return list.size();
	}

	public int getColumnCount() {
		return columns.length;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		Address Address = (Address) list.get(rowIndex);
		return getPropertyValueByCol(Address, columnIndex);
	}

	public void addList(int index, Address Address) {
		if (index < 0 || index > list.size() - 1) {
			list.add(Address);
			fireTableRowsInserted(list.size(), list.size());
		} else {
			list.add(index, Address);
			fireTableRowsInserted(index, index);
		}
	}

	public boolean deleteList(int index) {
		if (index >= 0 && index < list.size()) {
			list.remove(index);
			fireTableRowsDeleted(index, index);
			return true;
		} else
			return false;
	}

	public boolean updateList(int index, Address Address) {
		if (index >= 0 && index < list.size()) {
			list.set(index, Address);
			fireTableRowsUpdated(index, index);
			return true;
		} else
			return false;
	}

	public Address getRow(int index) {
		if (index >= 0 && index < list.size()) {
			return (Address) list.get(index);
		} else
			return null;
	}

	public List<Address> getList() {
		return this.list;
	}

	public void setList(List<Address> list) {
		this.list = list;
		fireTableStructureChanged();
	}

	public String getColumnName(int i) {
		return columns[i];
	}

	public void setColumn(String[] columns) {
		this.columns = columns;
	}
	
	public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
    }

	public Class<?> getColumnClass(int columnIndex) {
        return types[columnIndex];
    }
		
	private Object getPropertyValueByCol(Address Address, int columnIndex) {
		return null;
	}
}
